/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-17 16:49:46
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-17 18:06:12
 */
import 'package:flutter_data_center/model/wristband/wristband_model.dart';
import 'package:flutter_data_center/net/dio_utils.dart';
import 'package:get/get.dart';

class WristbandController extends GetxController {
  int _total = 0;
  int get total => _total;
  void getWristBandTotal() async {
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.wristbandTotal,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      _total = data['total'];
      update();
    }
  }

  // 手环列表
  List<WristbandModel> _list = [];
  List get list => _list;
  void getList() async {
    _list = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.wristbandList,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      for (var item in data) {
        _list.add(WristbandModel.fromJson((item)));
      }
      update();
    }
  }

  // 手环详情
  WristbandDetailModel detail;
  void getDetail() async {
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.wristbandDetail,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      detail = WristbandDetailModel.fromJson(data);
      update();
    }
  }
}
